(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

half(0) → 0
half(s(0)) → 0
half(s(s(x))) → s(half(x))
lastbit(0) → 0
lastbit(s(0)) → s(0)
lastbit(s(s(x))) → lastbit(x)
conv(0) → cons(nil, 0)
conv(s(x)) → cons(conv(half(s(x))), lastbit(s(x)))

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

half(0) → 0 [1]
half(s(0)) → 0 [1]
half(s(s(x))) → s(half(x)) [1]
lastbit(0) → 0 [1]
lastbit(s(0)) → s(0) [1]
lastbit(s(s(x))) → lastbit(x) [1]
conv(0) → cons(nil, 0) [1]
conv(s(x)) → cons(conv(half(s(x))), lastbit(s(x))) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

half(0) → 0 [1]
half(s(0)) → 0 [1]
half(s(s(x))) → s(half(x)) [1]
lastbit(0) → 0 [1]
lastbit(s(0)) → s(0) [1]
lastbit(s(s(x))) → lastbit(x) [1]
conv(0) → cons(nil, 0) [1]
conv(s(x)) → cons(conv(half(s(x))), lastbit(s(x))) [1]

The TRS has the following type information:
half :: 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
lastbit :: 0:s → 0:s
conv :: 0:s → nil:cons
cons :: nil:cons → 0:s → nil:cons
nil :: nil:cons

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:
none

And the following fresh constants: none

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

half(0) → 0 [1]
half(s(0)) → 0 [1]
half(s(s(x))) → s(half(x)) [1]
lastbit(0) → 0 [1]
lastbit(s(0)) → s(0) [1]
lastbit(s(s(x))) → lastbit(x) [1]
conv(0) → cons(nil, 0) [1]
conv(s(x)) → cons(conv(half(s(x))), lastbit(s(x))) [1]

The TRS has the following type information:
half :: 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
lastbit :: 0:s → 0:s
conv :: 0:s → nil:cons
cons :: nil:cons → 0:s → nil:cons
nil :: nil:cons

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

0 => 0
nil => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

conv(z) -{ 1 }→ 1 + conv(half(1 + x)) + lastbit(1 + x) :|: x >= 0, z = 1 + x
conv(z) -{ 1 }→ 1 + 0 + 0 :|: z = 0
half(z) -{ 1 }→ 0 :|: z = 0
half(z) -{ 1 }→ 0 :|: z = 1 + 0
half(z) -{ 1 }→ 1 + half(x) :|: x >= 0, z = 1 + (1 + x)
lastbit(z) -{ 1 }→ lastbit(x) :|: x >= 0, z = 1 + (1 + x)
lastbit(z) -{ 1 }→ 0 :|: z = 0
lastbit(z) -{ 1 }→ 1 + 0 :|: z = 1 + 0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V),0,[half(V, Out)],[V >= 0]).
eq(start(V),0,[lastbit(V, Out)],[V >= 0]).
eq(start(V),0,[conv(V, Out)],[V >= 0]).
eq(half(V, Out),1,[],[Out = 0,V = 0]).
eq(half(V, Out),1,[],[Out = 0,V = 1]).
eq(half(V, Out),1,[half(V1, Ret1)],[Out = 1 + Ret1,V1 >= 0,V = 2 + V1]).
eq(lastbit(V, Out),1,[],[Out = 0,V = 0]).
eq(lastbit(V, Out),1,[],[Out = 1,V = 1]).
eq(lastbit(V, Out),1,[lastbit(V2, Ret)],[Out = Ret,V2 >= 0,V = 2 + V2]).
eq(conv(V, Out),1,[],[Out = 1,V = 0]).
eq(conv(V, Out),1,[half(1 + V3, Ret010),conv(Ret010, Ret01),lastbit(1 + V3, Ret11)],[Out = 1 + Ret01 + Ret11,V3 >= 0,V = 1 + V3]).
input_output_vars(half(V,Out),[V],[Out]).
input_output_vars(lastbit(V,Out),[V],[Out]).
input_output_vars(conv(V,Out),[V],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [half/2]
1. recursive : [lastbit/2]
2. recursive [non_tail] : [conv/2]
3. non_recursive : [start/1]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into half/2
1. SCC is partially evaluated into lastbit/2
2. SCC is partially evaluated into conv/2
3. SCC is partially evaluated into start/1

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations half/2
* CE 7 is refined into CE [13]
* CE 6 is refined into CE [14]
* CE 5 is refined into CE [15]


### Cost equations --> "Loop" of half/2
* CEs [14] --> Loop 10
* CEs [15] --> Loop 11
* CEs [13] --> Loop 12

### Ranking functions of CR half(V,Out)
* RF of phase [12]: [V-1]

#### Partial ranking functions of CR half(V,Out)
* Partial RF of phase [12]:
- RF of loop [12:1]:
V-1


### Specialization of cost equations lastbit/2
* CE 10 is refined into CE [16]
* CE 9 is refined into CE [17]
* CE 8 is refined into CE [18]


### Cost equations --> "Loop" of lastbit/2
* CEs [17] --> Loop 13
* CEs [18] --> Loop 14
* CEs [16] --> Loop 15

### Ranking functions of CR lastbit(V,Out)
* RF of phase [15]: [V-1]

#### Partial ranking functions of CR lastbit(V,Out)
* Partial RF of phase [15]:
- RF of loop [15:1]:
V-1


### Specialization of cost equations conv/2
* CE 12 is refined into CE [19,20,21,22,23]
* CE 11 is refined into CE [24]


### Cost equations --> "Loop" of conv/2
* CEs [24] --> Loop 16
* CEs [23] --> Loop 17
* CEs [22] --> Loop 18
* CEs [21] --> Loop 19
* CEs [20] --> Loop 20
* CEs [19] --> Loop 21

### Ranking functions of CR conv(V,Out)
* RF of phase [17,18,19,20]: [V-1]

#### Partial ranking functions of CR conv(V,Out)
* Partial RF of phase [17,18,19,20]:
- RF of loop [17:1,18:1]:
V/2-1
- RF of loop [19:1]:
2*V-5
- RF of loop [20:1]:
V-1


### Specialization of cost equations start/1
* CE 2 is refined into CE [25,26,27,28]
* CE 3 is refined into CE [29,30,31,32]
* CE 4 is refined into CE [33,34,35]


### Cost equations --> "Loop" of start/1
* CEs [27,28,31,32,35] --> Loop 22
* CEs [26,30,34] --> Loop 23
* CEs [25,29,33] --> Loop 24

### Ranking functions of CR start(V)

#### Partial ranking functions of CR start(V)


Computing Bounds
=====================================

#### Cost of chains of half(V,Out):
* Chain [[12],11]: 1*it(12)+1
Such that:it(12) =< 2*Out

with precondition: [V=2*Out,V>=2]

* Chain [[12],10]: 1*it(12)+1
Such that:it(12) =< 2*Out

with precondition: [V=2*Out+1,V>=3]

* Chain [11]: 1
with precondition: [V=0,Out=0]

* Chain [10]: 1
with precondition: [V=1,Out=0]


#### Cost of chains of lastbit(V,Out):
* Chain [[15],14]: 1*it(15)+1
Such that:it(15) =< V

with precondition: [Out=0,V>=2]

* Chain [[15],13]: 1*it(15)+1
Such that:it(15) =< V

with precondition: [Out=1,V>=3]

* Chain [14]: 1
with precondition: [V=0,Out=0]

* Chain [13]: 1
with precondition: [V=1,Out=1]


#### Cost of chains of conv(V,Out):
* Chain [[17,18,19,20],21,16]: 3*it(17)+3*it(18)+3*it(19)+3*it(20)+2*s(17)+2*s(18)+4*s(21)+4
Such that:aux(5) =< 2*V+4
aux(13) =< V
aux(14) =< 2*V
aux(15) =< 3*V
aux(16) =< 4*V
aux(17) =< V/2
it(19) =< aux(14)
it(17) =< aux(13)
it(18) =< aux(13)
it(19) =< aux(13)
it(20) =< aux(13)
it(20) =< aux(5)
s(22) =< aux(5)
it(20) =< aux(14)
s(22) =< aux(14)
it(18) =< aux(15)
it(19) =< aux(15)
s(18) =< aux(15)
it(20) =< aux(15)
it(18) =< aux(16)
it(19) =< aux(16)
s(17) =< aux(16)
it(20) =< aux(16)
it(17) =< aux(17)
it(18) =< aux(17)
s(21) =< s(22)

with precondition: [Out>=4,V+8>=2*Out,V+2>=Out]

* Chain [21,16]: 4
with precondition: [V=1,Out=3]

* Chain [16]: 1
with precondition: [V=0,Out=1]


#### Cost of chains of start(V):
* Chain [24]: 1
with precondition: [V=0]

* Chain [23]: 4
with precondition: [V=1]

* Chain [22]: 4*s(25)+3*s(35)+3*s(36)+3*s(37)+3*s(38)+2*s(40)+2*s(41)+4*s(42)+4
Such that:s(31) =< 2*V
s(29) =< 2*V+4
s(32) =< 3*V
s(33) =< 4*V
s(34) =< V/2
aux(18) =< V
s(25) =< aux(18)
s(35) =< s(31)
s(36) =< aux(18)
s(37) =< aux(18)
s(35) =< aux(18)
s(38) =< aux(18)
s(38) =< s(29)
s(39) =< s(29)
s(38) =< s(31)
s(39) =< s(31)
s(37) =< s(32)
s(35) =< s(32)
s(40) =< s(32)
s(38) =< s(32)
s(37) =< s(33)
s(35) =< s(33)
s(41) =< s(33)
s(38) =< s(33)
s(36) =< s(34)
s(37) =< s(34)
s(42) =< s(39)

with precondition: [V>=2]


Closed-form bounds of start(V):
-------------------------------------
* Chain [24] with precondition: [V=0]
- Upper bound: 1
- Complexity: constant
* Chain [23] with precondition: [V=1]
- Upper bound: 4
- Complexity: constant
* Chain [22] with precondition: [V>=2]
- Upper bound: 41*V+20
- Complexity: n

### Maximum cost of start(V): 41*V+20
Asymptotic class: n
* Total analysis performed in 263 ms.

(10) BOUNDS(1, n^1)